package com.world.rickcloudendpoint.common.utils;

import lombok.Getter;

import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoField;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * 时间工具类，提供时间格式转换功能
 *
 * @author Ja
 */
public final class DateTimeUtils {

    public enum TIME_UNIT {
        MILLIS, SECS, MINS, HOURS, DAYS, MONTH, YEAR
    }

    private static String INVALID_DATE_ERR = "Please provide a valid Date.";
    private static String INVALID_CAL_ERR = "Please provide a valid Calendar.";
    private static String STRING_FMT_ERR = "Please provide a valid String.";

    private static final long MILLIS_IN_SEC = 1000;
    private static final long MILLIS_IN_MIN = MILLIS_IN_SEC * 60;
    private static final long MILLIS_IN_HOUR = MILLIS_IN_MIN * 60;
    private static final long MILLIS_IN_DAY = MILLIS_IN_HOUR * 24;

    /**
     * 年月日时分秒毫秒 显示格式
     */
    public static String DATE_TIME_FORMAT_YYYYMMDDHHMMSSSSS = "yyyyMMddHHmmssSSS";
    /**
     * 年月日时分秒毫秒 显示格式
     */
    public static String DATE_TIME_FORMAT_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    /**
     * 年-月-日 时:分:秒 显示格式
     */
    public static final String PATTERN = "yyyy-MM-dd HH:mm:ss";
    public static final String STANDARD_FORMAT = "yyyy-MM-dd HH:mm:ss";
    /**
     * 年-月-日 显示格式
     */
    public static final String PATTERN_DAY = "yyyy-MM-dd";

    public static final String PATTERN_DAY_S = "yyyyMMdd";

    public static final String UEND_TIME = "23:59:59";

    public static final String REG = "(\\d{4})(\\d{2})(\\d{2})(\\d{2})(\\d{2})(\\d{2})";

    public static final String REG_REPLACE = "$1-$2-$3 $4:$5:$6";

    public static final String chinaZone = "Asia/Shanghai";
    public static final String americanZone = "America/Los_Angeles";

    /**
     * 将yyyyMMddHHmmss转换成yyyy-MM-dd HH:mm:ss
     *
     * @param date
     * @return
     */
    public static String longTimeParseTimeStr(String date) {
        return date.replaceAll(REG, REG_REPLACE);
    }

    /**
     * 将两个时间字符串进行比较 start < end 返回 true 其他返回 false
     *
     * @param start 格式:yyyy-MM-dd HH:mm:ss
     * @param end 格式:yyyy-MM-dd HH:mm:ss
     * @return
     */
    public static boolean compareTwoTimes(String start, String end) {
        start = longTimeParseTimeStr(start);
        end = longTimeParseTimeStr(end);
        Date d1 = stringToDate(start, PATTERN);
        if (d1 == null) {
            return false;
        }
        Date d2 = stringToDate(end, PATTERN);
        if (d2 == null) {
            return false;
        }

        return d1.getTime() < d2.getTime();

    }

    /**
     * Date类型转为指定格式的String类型
     *
     * @param source
     * @param pattern
     * @return
     */
    public static String dateToString(Date source, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(source);
    }

    /**
     * unix时间戳转为指定格式的String类型
     *
     *
     * System.currentTimeMillis()获得的是是从1970年1月1日开始所经过的毫秒数 unix时间戳:是从1970年1月1日（UTC/GMT的午夜）开始所经过的秒数,不考虑闰秒
     *
     * @param source
     * @param pattern
     * @return
     */
    public static String timeStampToString(long source, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = new Date(source * 1000);
        return simpleDateFormat.format(date);
    }

    /**
     * 时间戳转年月日时分秒毫秒
     * @param source 时间戳，单位：ms
     * @return 年月日时分秒毫秒
     */
    public static YmdHmsMillis timeStampToYmdHmsMillis(long source) {
        Date date = new Date(source);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        int year = cal.get(Calendar.YEAR);
        int month = cal.get(Calendar.MONTH) + 1; // Note: zero based!
        int day = cal.get(Calendar.DAY_OF_MONTH);
        int hour = cal.get(Calendar.HOUR_OF_DAY);
        int minute = cal.get(Calendar.MINUTE);
        int second = cal.get(Calendar.SECOND);
        int millis = cal.get(Calendar.MILLISECOND);

        return new YmdHmsMillis(year, month, day, hour, minute, second, millis);
    }

    public static YmdHmsMillis timeStampToYmdHmsMillis(LocalDateTime time){
        int year = time.getYear();
        int month = time.getMonthValue();
        int day = time.getDayOfMonth();
        int hour = time.getHour();
        int minute = time.getMinute();
        int second = time.getSecond();
        int millis = time.get(ChronoField.MILLI_OF_SECOND);
        return new YmdHmsMillis(year, month, day, hour, minute, second, millis);
    }

    public static long ymdHmsMillisToTimeStamp(YmdHmsMillis yhm, String zone){
        LocalDateTime ldt =LocalDateTime.of(yhm.getYear(), yhm.getMonth(), yhm.getDay(), yhm.getHour(), yhm.getMinute(), yhm.getSecond());
        ZonedDateTime zdt = ldt.atZone(ZoneId.of(zone));
        long millis = zdt.toInstant().toEpochMilli();
        return millis;
    }
    /**
     * 单独的时间：年、月、日、时、分、秒、毫秒
     */
    public static final class YmdHmsMillis{
        @Getter
        int year;
        @Getter
        int month;
        @Getter
        int day;
        @Getter
        int hour;
        @Getter
        int minute;
        @Getter
        int second;
        @Getter
        int millis;

        public YmdHmsMillis(int year, int month, int day, int hour, int minute, int second, int millis) {
            this.year = year;
            this.month = month;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
            this.millis = millis;
        }
    }

    /**
     * 将日期转换为时间戳(unix时间戳,单位秒)
     *
     * @param date
     * @return
     */
    public static long dateToTimeStamp(Date date) {
        Timestamp timestamp = new Timestamp(date.getTime());
        return timestamp.getTime() / 1000;
    }

    /**
     * 字符串转换为对应日期(可能会报错异常)
     *
     * @param source
     * @param pattern
     * @return
     */
    public static Date stringToDate(String source, String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = simpleDateFormat.parse(source);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return date;
    }

    /**
     * 获得当前时间对应的指定格式
     *
     * @param pattern
     * @return
     */
    public static String currentFormatDate(String pattern) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
        return simpleDateFormat.format(new Date());

    }

    /**
     * 获得当前unix时间戳(单位秒)
     *
     * @return 当前unix时间戳
     */
    public static long currentTimeStamp() {
        return System.currentTimeMillis() / 1000;
    }


    /**
     * Formats a Date object, given a format string consistent with <code>SimpleDateFormat</code> class.
     *
     * @param date - A Date object to be formatted.
     * @param format - The desired format (for <code>SimpleDateFormat</code> class.
     * @return A date formatted as a string.
     */
    public static String formatDate(Date date, String format) {
        if (date == null) {
            throw new NullPointerException(INVALID_DATE_ERR);
        }
        if (format == null) {
            throw new NullPointerException(STRING_FMT_ERR);
        }
        if (format.length() == 0) {
            throw new IllegalArgumentException(STRING_FMT_ERR);
        }

        SimpleDateFormat dateFormatter = new SimpleDateFormat(format);
        return dateFormatter.format(date);
    }

    /**
     * Creates a date from a formatted string consistent with the <code> SimpleDateFormat</code> class.
     *
     * @param formattedString - A formatted date as a string consistent with the <code>SimpleDateFormat</code> class.
     * @return A Date object created from the date in the formattedString.
     * @throws ParseException
     */
    public static Date getDateFromString(String formattedString) throws ParseException {
        if (formattedString == null) {
            throw new NullPointerException(STRING_FMT_ERR);
        }
        if (formattedString.length() == 0) {
            throw new IllegalArgumentException(STRING_FMT_ERR);
        }

        SimpleDateFormat dateFormatter = new SimpleDateFormat();

        return dateFormatter.parse(formattedString);

    }

    /**
     * Formats a Calendar object, given a format string consistent with the <code> SimpleDateFormat</code> class..
     *
     * @param calendar - A Calendar object to be formatted.
     * @param format - The desired format consistent with the <code> SimpleDateFormat</code> class.
     * @return A date formatted as a string.
     */
    public static String formatDate(Calendar calendar, String format) {
        if (calendar == null) {
            throw new NullPointerException(INVALID_CAL_ERR);
        }
        if (format == null) {
            throw new NullPointerException(STRING_FMT_ERR);
        }
        if (format.length() == 0) {
            throw new IllegalArgumentException(STRING_FMT_ERR);
        }

        SimpleDateFormat dateFormatter = new SimpleDateFormat(format);

        return dateFormatter.format(calendar.getTime());
    }

    /**
     * Creates a date from a formatted string consistent with the <code> SimpleDateFormat</code> class.
     *
     * @param formattedString - A formatted date as a string consistent with the <code>impleDateFormat</code> class.
     * @return A Calendar object created from the date in the formattedString.
     * @throws ParseException
     */
    public static Calendar getCalendarFromString(String formattedString) throws ParseException {
        if (formattedString == null) {
            throw new NullPointerException(STRING_FMT_ERR);
        }
        if (formattedString.length() == 0) {
            throw new IllegalArgumentException(STRING_FMT_ERR);
        }

        SimpleDateFormat dateFormatter = new SimpleDateFormat(formattedString);
        Date date = dateFormatter.parse(formattedString);
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);

        return cal;
    }

    /**
     * Formats the specified calendar into a string with short date format (MM/dd/yyyy). For example, 01/01/2013.
     *
     * @param cal - The calendar to format.
     * @return A String formatted into a short date (MM/dd/yyyy).
     */
    public static String formatToShortDate(Calendar cal) {
        if (cal == null) {
            throw new NullPointerException(INVALID_CAL_ERR);
        }
        return formatDate(cal, "MM/dd/yyyy");
    }

    /**
     * Formats the specified date into a string with short date format (MM/dd/yyyy). For example, 01/01/2013.
     *
     * @param date - The date to format.
     * @return A String formatted into a short date (MM/dd/yyyy).
     */
    public static String formatToShortDate(Date date) {
        if (date == null) {
            throw new NullPointerException(INVALID_DATE_ERR);
        }
        return formatDate(date, "MM/dd/yyyy");
    }

    /**
     * Formats the specified calendar into a string with short time format (HH:mm aa). For example, 09:00 AM.
     *
     * @param cal - The calendar to format.
     * @return A String formatted into a short time.
     */
    public static String formatToShortTime(Calendar cal) {
        if (cal == null) {
            throw new NullPointerException(INVALID_CAL_ERR);
        }
        return formatDate(cal, "hh:mm aa");
    }

    /**
     * Formats the specified date into a string with short time format (HH:mm aa). For example, 09:00 AM.
     *
     * @param date - The date to format.
     * @return A String formatted into a short time.
     */
    public static String formatToShortTime(Date date) {
        if (date == null) {
            throw new NullPointerException(INVALID_DATE_ERR);
        }
        return formatDate(date, "hh:mm aa");
    }


    /**
     * Returns the time difference between two calendars in the specified time unit. If the first calendar's date occurs after the second calendar's,
     * returns a negative value.
     *
     * @param cal1 - The first calendar.
     * @param cal2 - The second calendar.
     * @param timeUnit - The <code>TIME_UNIT</code> to return the difference in.
     * @return Time difference between the calendars. If cal1 is after cal2, returns a negative value.
     */
    public static long getDiff(Calendar cal1, Calendar cal2,
                               TIME_UNIT timeUnit) {

        if (cal1 == null || cal2 == null || timeUnit == null) {
            throw new NullPointerException(INVALID_DATE_ERR);
        }

        long timeDiffInMillis = cal2.getTimeInMillis() - cal1.getTimeInMillis();

        switch (timeUnit) {
            case MILLIS:
                return timeDiffInMillis;
            case SECS:
                return timeDiffInMillis / MILLIS_IN_SEC;
            case MINS:
                return timeDiffInMillis / MILLIS_IN_MIN;
            case HOURS:
                return timeDiffInMillis / MILLIS_IN_HOUR;
            case DAYS:
                return timeDiffInMillis / MILLIS_IN_DAY;
            default:
                return timeDiffInMillis;
        }

    }

    /**
     * Returns the time difference between two dates in the specified time unit. If the first date occurs after the second date, returns a negative.
     *
     * @param date1 - The first date.
     * @param date2 - The second date.
     * @param timeUnit - The <code>TIME_UNIT</code> to return the difference in.
     * @return Time difference between the calendars. If date1 is after date2, returns a negative value.
     */
    public static long getDiff(Date date1, Date date2, TIME_UNIT timeUnit) {
        if (date1 == null || date2 == null || timeUnit == null) {
            throw new NullPointerException();
        }

        Calendar cal1 = Calendar.getInstance();
        cal1.setTime(date1);

        Calendar cal2 = Calendar.getInstance();
        cal2.setTime(date2);

        return getDiff(cal1, cal2, timeUnit);

    }

    /**
     * Given a <code>Calendar</code>, adds the given amount of time to the calendar. If the given amount of time is negative, it subtracts the time,
     * producing a date earlier than the given date.
     *
     * @param cal - The Calendar to add time to.
     * @param amount - The amount of time to add, in the time unit specified in <code>timeUnit</code>.
     * @param timeUnit - The unit of time to add.
     * @return A Calendar with the new date/time.
     */
    public static Calendar addTime(Calendar cal, long amount, TIME_UNIT timeUnit) {
        if (cal == null) {
            throw new NullPointerException(INVALID_CAL_ERR);
        }
        switch (timeUnit) {
            case MILLIS:
                cal.setTimeInMillis(cal.getTimeInMillis() + amount);
                return cal;
            case SECS:
                long secondsToAdd = cal.getTimeInMillis() + amount * MILLIS_IN_SEC;
                cal.setTimeInMillis(secondsToAdd);
                return cal;
            case MINS:
                long minsToAdd = cal.getTimeInMillis() + amount * MILLIS_IN_MIN;
                cal.setTimeInMillis(minsToAdd);
                return cal;
            case HOURS:
                long hoursToAdd = cal.getTimeInMillis() + amount * MILLIS_IN_HOUR;
                cal.setTimeInMillis(hoursToAdd);
                return cal;
            case DAYS:
                long daysToAdd = cal.getTimeInMillis() + amount * MILLIS_IN_DAY;
                cal.setTimeInMillis(daysToAdd);
                return cal;
            default:
                return null;
        }
    }

    /**
     * Given a <code>Date</code>, adds the given amount of time to the date. If the given amount of time is negative, it subtracts the time, producing
     * a date earlier than the given date.
     *
     * @param date - The <code>Date</code> to add time to.
     * @param amount - The amount of time to add, in the time unit specified in <code>timeUnit</code>.
     * @param timeUnit - The unit of time to add.
     * @return A <code>Date</code> with the new date/time.
     */
    public static Date addTime(Date date, long amount, TIME_UNIT timeUnit) {
        if (date == null) {
            throw new NullPointerException(INVALID_DATE_ERR);
        }
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        addTime(cal, amount, timeUnit);
        return cal.getTime();
    }


    /**
     * 获取当前时间的秒数
     *
     * @return 当前时间的秒数
     */
    public static long getSecond() {
        long time = System.currentTimeMillis();
        return time / 1000;
    }


    /**
     * 获取两个日期之间的所有天，包括开始和结束日期
     * @param begin
     * @param end
     * @return
     */
    public static List<Date> getBetweenDates(Date begin, Date end){
        List<Date> result = new ArrayList<>();
        Calendar tem = Calendar.getInstance();
        tem.setTime(begin);

        while (begin.getTime() <= end.getTime()){
            result.add(tem.getTime());
            tem.add(Calendar.DAY_OF_YEAR, 1);
            begin = tem.getTime();
        }
        return result;
    }

    /**
     * 获取两个日期之间的所有天，包括开始和结束日期
     * @param begin
     * @param end
     * @return
     */
    public static List<String> getBetweenDatesStr(Date begin, Date end){
        List<String> result = new ArrayList<>();
        Calendar tem = Calendar.getInstance();
        tem.setTime(begin);

        while (begin.getTime() <= end.getTime()){
            result.add(DateTimeUtils.dateToString(tem.getTime(), DateTimeUtils.PATTERN_DAY_S));
            tem.add(Calendar.DAY_OF_YEAR, 1);
            begin = tem.getTime();
        }
        return result;
    }

    /**
     * 获取两个时间点的差值(在指定时区下)
     * @param startTime 开始时间
     * @param endTime 介绍时间
     * @param timeZone 时区 例如: +08:00
     * @return 差值
     */
    public static long getDiffInUTC(String startTime, String endTime, String timeZone) {
        long startTimeSecond = LocalDateTime.parse(startTime, DateTimeFormatter.ofPattern(DateTimeUtils.PATTERN)).toInstant(ZoneOffset.of(timeZone))
                .getEpochSecond();
        long endTimeSecond = LocalDateTime.parse(endTime, DateTimeFormatter.ofPattern(DateTimeUtils.PATTERN)).toInstant(ZoneOffset.of(timeZone))
                .getEpochSecond();
        return  endTimeSecond - startTimeSecond;
    }

    /**
     * 字符串时间按指定时区转换成该时区下的时间
     * @param time 字符串时间
     * @param timeZone 指定的时区
     * @return 指定时区时间
     */
    public static ZonedDateTime strToZonedDateTime(String time, String timeZone) {
        LocalDateTime localTime = LocalDateTime.parse(time, DateTimeFormatter.ofPattern(DateTimeUtils.PATTERN));
        ZonedDateTime zoneTime = ZonedDateTime.of(localTime, ZoneId.of(timeZone));
        return zoneTime;
    }

    /**
     * 获取指定时间前一天时间
     * @param dateTime 时间
     * @return
     */
    public static String getTheDateBefore(String dateTime){
        Date date = stringToDate(dateTime, DateTimeUtils.PATTERN);

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(Calendar.DAY_OF_MONTH, -1);
        Date before = calendar.getTime();

        // 格式化前一天
        SimpleDateFormat sdf = new SimpleDateFormat(DateTimeUtils.PATTERN);
        return sdf.format(before);
    }


    /**
     * 获取与指定日期间隔给定天数的日期.
     * @param specifiedDay    给定的字符串格式日期，支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss",
     *            "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
     *            "yyyy/MM/dd HH:mm"
     * @param num   间隔天数
     * @return String 间隔指定天数之前的日期
     * @since 1.0
     * 返回结果是 "yyyy-MM-dd"
     */
    public static String getSpecifiedDayBefore(String specifiedDay, int num) {
        Date specifiedDate = stringToDate(specifiedDay, DateTimeUtils.PATTERN);
        Calendar c = Calendar.getInstance();
        c.setTime(specifiedDate);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day - num);
        String dayAfter = formatDate(c.getTime(), DateTimeUtils.PATTERN_DAY);
        return dayAfter;
    }



    /**
     * 获取与指定日期间隔给定天数的日期.
     * @param specifiedDay    给定的字符串格式日期，支持的日期字符串格式包括"yyyy-MM-dd","yyyy-MM-dd HH:mm:ss",
     *            "yyyy-MM-dd HH:mm", "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss",
     *            "yyyy/MM/dd HH:mm"
     * @param num   间隔天数
     * @return String 间隔指定天数之后的日期
     * @since 1.0
     * 返回结果是 "yyyy-MM-dd"
     */
    public static String getSpecifiedDayAfter(String specifiedDay, int num) {
        Date specifiedDate = stringToDate(specifiedDay, DateTimeUtils.PATTERN);
        Calendar c = Calendar.getInstance();
        c.setTime(specifiedDate);
        int day = c.get(Calendar.DATE);
        c.set(Calendar.DATE, day + num);
        String dayAfter = formatDate(c.getTime(), DateTimeUtils.PATTERN_DAY);
        return dayAfter;
    }


    /**
     * 返回昨天
     * @return 返回结果是 "yyyy-MM-dd"
     */
    public static String getYesterday(){
        String today = DateTimeUtils.dateToString(new Date(), DateTimeUtils.PATTERN);
        String yesterday = DateTimeUtils.getSpecifiedDayBefore(today, 1);
        return  yesterday;
    }



    /**
     * 计算两个日期之间相差天数.
     * @param start     计算开始日期
     * @param end       计算结束日期
     * @return long 相隔天数
     * @since 1.0
     * 问题: 当间隔在一天之内时,返回值为0
     */
    public static long getDaysBetween(Date start, Date end) {

        long diff=0;
        if(start != null && end != null) {
            diff = (long) ((end.getTime() - start.getTime()) / (1000*3600*24));
        }
        return diff;
    }


    /**
     * 计算两个日期之间相差天数.
     * @param start 计算开始日期
     * @param end   计算结束日期
     * @return 相隔天数
     * 问题: 当间隔在一天之内时,返回值为0
     */
    public static long getDaysBetween(String start, String end) {
        Date s = stringToDate(start, DateTimeUtils.PATTERN);
        Date e = stringToDate(end, DateTimeUtils.PATTERN);
        long diff=0;
        if(s != null && e != null) {
            diff = (long) ((e.getTime() - s.getTime()) / (1000*3600*24));
        }
        return diff;
    }

    /**
     * 是否间距 3600 * 24 * 3 秒,就是间隔三天判断
     * @param start 开始时间
     * @param end 结束时间
     * @return true: 在3天内, false: 在3天外或3天
     */
    public static boolean isThreeDaysApart(String start, String end){
        Date s = stringToDate(start, DateTimeUtils.PATTERN);
        Date e = stringToDate(end, DateTimeUtils.PATTERN);
        if (s != null && e != null){
            long diff = (long) ((e.getTime() - s.getTime()) / 1000);
            long result =  diff - 3600*24*3 + 1;
            if (result >= 0){
                return false;
            }else {
                return true;
            }
        }
        return false;
    }


    /**
     * @Description 两个时间范围 是否为当天24h内
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     * boolean
     */
    public static boolean isAtToday(String startTime, String endTime) {
        Date start = stringToDate(startTime,  DateTimeUtils.PATTERN_DAY);
        Date end = stringToDate(endTime, DateTimeUtils.PATTERN_DAY);
        Date now = new Date(System.currentTimeMillis());
        String startStr = dateToString(start, DateTimeUtils.PATTERN_DAY);
        String endStr = dateToString(end, DateTimeUtils.PATTERN_DAY);
        String nowStr = dateToString(now, DateTimeUtils.PATTERN_DAY);
        if (startStr.equals(endStr) && startStr.equals(nowStr)){
            return true;
        }
        return false;
    }


    /**
     * @Description 两个时间范围 是否包含当天
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return
     */
    public static boolean isIncludeToday(String startTime, String endTime) {
        Date start = stringToDate(startTime,  DateTimeUtils.PATTERN_DAY);
        Date end = stringToDate(endTime, DateTimeUtils.PATTERN_DAY);
        Date now = new Date(System.currentTimeMillis());
        String startStr = dateToString(start, DateTimeUtils.PATTERN_DAY);
        String endStr = dateToString(end, DateTimeUtils.PATTERN_DAY);
        String nowStr = dateToString(now, DateTimeUtils.PATTERN_DAY);
        if (!startStr.equals(nowStr) && endStr.equals(nowStr)){
            return true;
        }
        return false;
    }

}
